<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=9" >

<title>Simulations Causal Forests</title>

<style type="text/css">
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: rgb(50%, 0%, 50%);
}

pre {	
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

</style>

<!-- Styles for R syntax highlighter -->
<style type="text/css">
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
</style>

<!-- R syntax highlighter -->
<script type="text/javascript">
var hljs=new function(){function m(p){return p.replace(/&/gm,"&amp;").replace(/</gm,"&lt;")}function f(r,q,p){return RegExp(q,"m"+(r.cI?"i":"")+(p?"g":""))}function b(r){for(var p=0;p<r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName=="CODE"){return q}if(!(q.nodeType==3&&q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p="";for(var r=0;r<t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,"")}p+=q}else{if(t.childNodes[r].nodeName=="BR"){p+="\n"}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,"\n")}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q<r.length;q++){var p=r[q].replace(/^language-/,"");if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r<s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName=="BR"){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:"start",offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:"stop",offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z="";var s=[];function u(){if(y.length&&w.length){if(y[0].offset!=w[0].offset){return(y[0].offset<w[0].offset)?y:w}else{return w[0].event=="start"?y:w}}else{return y.length?y:w}}function t(D){var A="<"+D.nodeName.toLowerCase();for(var B=0;B<D.attributes.length;B++){var C=D.attributes[B];A+=" "+C.nodeName.toLowerCase();if(C.value!==undefined&&C.value!==false&&C.value!==null){A+='="'+m(C.value)+'"'}}return A+">"}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event=="start"){z+=t(v.node);s.push(v.node)}else{if(v.event=="stop"){var p,r=s.length;do{r--;p=s[r];z+=("</"+p.nodeName.toLowerCase()+">")}while(p!=v.node);s.splice(r,1);while(r<s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w="keyword"}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b="\\b("+s.join("|")+")\\s"}x.bR=f(y,x.b?x.b:"\\B|\\b");if(!x.e&&!x.eW){x.e="\\B|\\b"}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t<x.c.length;t++){if(x.c[t]=="self"){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L<M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&&D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&&L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L<N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join("|"),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),"",true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&&M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r="";var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+='<span class="'+N[0]+'">'+M[0]+"</span>"}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&&e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?'<span class="'+M.cN+'">':"";if(M.rB){y+=L;M.buffer=""}else{if(M.eB){y+=m(r)+L;M.buffer=""}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?"</span>":"";if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L>1){O=D[D.length-2].cN?"</span>":"";y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer="";if(r.starts){I(r.starts,"")}return R.rE}if(w(M,R)){throw"Illegal"}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y="";try{var s,u=0;E.dM.buffer="";do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length>1){throw"Illegal"}return{r:A,keyword_count:x,value:y}}catch(H){if(H=="Illegal"){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r>r.keyword_count+r.r){r=s}if(s.keyword_count+s.r>p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((<[^>]+>|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,"<br>")}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement("pre");s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match("(\\s|^)(language-)?"+v+"(\\s|$)")){u=u?(u+" "+v):v}if(/MSIE [678]/.test(navigator.userAgent)&&t.tagName=="CODE"&&t.parentNode.tagName=="PRE"){s=t.parentNode;var p=document.createElement("div");p.innerHTML="<pre><code>"+y.value+"</code></pre>";t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName("pre");for(var p=0;p<r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener("DOMContentLoaded",o,false);window.addEventListener("load",o,false)}else{if(window.attachEvent){window.attachEvent("onload",o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.ER="(?![\\s\\S])";this.BE={b:"\\\\.",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{"false":1,"int":1,"float":1,"while":1,"private":1,"char":1,"catch":1,"export":1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,"const":1,struct:1,"for":1,static_cast:2,union:1,namespace:1,unsigned:1,"long":1,"throw":1,"volatile":2,"static":1,"protected":1,bool:1,template:1,mutable:1,"if":1,"public":1,friend:2,"do":1,"return":1,"goto":1,auto:1,"void":2,"enum":1,"else":1,"break":1,"new":1,extern:1,using:1,"true":1,"class":1,asm:1,"case":1,typeid:1,"short":1,reinterpret_cast:2,"default":1,"double":1,register:1,explicit:1,signed:1,typename:1,"try":1,"this":1,"switch":1,"continue":1,wchar_t:1,inline:1,"delete":1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:"</",c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:"string",b:"'\\\\?.",e:"'",i:"."},{cN:"number",b:"\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)"},hljs.CNM,{cN:"preprocessor",b:"#",e:"$"},{cN:"stl_container",b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:a,r:10,c:["self"]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:"number",b:"\\b0[xX][0-9a-fA-F]+[Li]?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\b\\d+\\.(?!\\d)(?:i\\b)?",e:hljs.IMMEDIATE_RE,r:1},{cN:"number",b:"\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"number",b:"\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"keyword",b:"(?:tryCatch|library|setGeneric|setGroupGeneric)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\.",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\.\\.\\d+(?![\\w.])",e:hljs.IMMEDIATE_RE,r:10},{cN:"keyword",b:"\\b(?:function)",e:hljs.IMMEDIATE_RE,r:2},{cN:"keyword",b:"(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"literal",b:"(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b",e:hljs.IMMEDIATE_RE,r:10},{cN:"literal",b:"(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b",e:hljs.IMMEDIATE_RE,r:1},{cN:"identifier",b:"[a-zA-Z.][a-zA-Z0-9._]*\\b",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"<\\-(?!\\s*\\d)",e:hljs.IMMEDIATE_RE,r:2},{cN:"operator",b:"\\->|<\\-",e:hljs.IMMEDIATE_RE,r:1},{cN:"operator",b:"%%|~",e:hljs.IMMEDIATE_RE},{cN:"operator",b:">=|<=|==|!=|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||\\$|:",e:hljs.IMMEDIATE_RE,r:0},{cN:"operator",b:"%",e:"%",i:"\\n",r:1},{cN:"identifier",b:"`",e:"`",r:0},{cN:"string",b:'"',e:'"',c:[hljs.BE],r:0},{cN:"string",b:"'",e:"'",c:[hljs.BE],r:0},{cN:"paren",b:"[[({\\])}]",e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
</script>


<!-- MathJax scripts -->
<script type="text/javascript" src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>



</head>

<body>
<h2>Simulations Causal Forests</h2>

<p>#Variables
smsa66 lived in smsa in 1966 ?</p>

<p>smsa76 lived in smsa in 1976 ?</p>

<p>age76 age in 1976</p>

<p>daded dads education (imputed avg if missing)</p>

<p>south66 lived in south in 1966 ?</p>

<p>south76 lived in south in 1976 ?</p>

<p>lwage76 log wage in 1976 (outliers trimmed)</p>

<p>famed mom-dad education class (1-9)</p>

<p>black black ?</p>

<p>wage76 wage in 1976 (raw, cents per hour)</p>

<p>enroll76 enrolled in 1976 ?</p>

<p>kww the kww score</p>

<p>iqscore a normed IQ score</p>

<p>mar76 married in 1976 ?</p>

<p>libcrd14 library card in home at age 14 ?</p>

<p>exp76 experience in 1976</p>

<pre><code class="r">Schooling$high &lt;- 1*(Schooling$wage76 &gt; quantile(Schooling$wage76,0.8))
### train/test sample
set.seed(1789)
ind &lt;- sample(2, nrow(Schooling), replace=TRUE,prob=c(0.7,0.3))
trainData &lt;- Schooling[ind==1,]
testData &lt;-Schooling[ind==2, ]

formula1 &lt;- wage76~  iqscore + black + exp76+ age76
Tree1 &lt;- ctree(formula1, trainData    )
Tree1 &lt;- tree(formula1, trainData    )
summary(Tree1)
</code></pre>

<pre><code>## 
## Regression tree:
## tree(formula = formula1, data = trainData)
## Number of terminal nodes:  7 
## Residual mean deviance:  59100 = 85750000 / 1451 
## Distribution of residuals:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -642.90 -159.00  -33.55    0.00  121.70 1637.00
</code></pre>

<pre><code class="r">plot(Tree1)
text(Tree1, pretty=0)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-2"/></p>

<h1>crossvalidation error</h1>

<pre><code class="r">cv.Tree1 &lt;- cv.tree(Tree1)
## plot cross validation error cv.Tree1$dev as a function of size
plot(cv.Tree1$size,cv.Tree1$dev, type=&#39;b&#39;)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-3"/></p>

<pre><code class="r">prune.Tree1 &lt;- prune.tree(Tree1, best=5)
</code></pre>

<pre><code class="r">plot(prune.Tree1)
text(prune.Tree1, pretty=0)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-4"/></p>

<pre><code class="r">test_predict &lt;- predict(prune.Tree1, newdata= testData)
plot(test_predict, testData$wage76)
abline(0,1)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-5"/></p>

<pre><code class="r">mean((test_predict - testData$wage76)^2)
</code></pre>

<pre><code>## [1] 59304.88
</code></pre>

<h3>Forests</h3>

<pre><code class="r">RF1 &lt;- cforest(formula1, trainData, controls=cforest_control( mtry=4,mincriterion = 0)    )
test_predict &lt;- predict(RF1 ,newdata = testData, type = &quot;response&quot;)
</code></pre>

<pre><code class="r">plot(test_predict, testData$wage76)
abline(0,1)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-7"/></p>

<pre><code class="r">mean((test_predict - testData$wage76)^2)
</code></pre>

<pre><code>## [1] 50505.29
</code></pre>

<pre><code class="r">varimp(RF1 )
</code></pre>

<pre><code>##   iqscore     black     exp76     age76 
##  1462.498  4197.515 10680.731 36815.135
</code></pre>

<h4>classification tree</h4>

<pre><code class="r">formula1 &lt;- high~ iqscore + black + exp76+ age76
Tree1 &lt;- ctree(formula1, trainData    )
# Tree1 &lt;- tree(formula1, trainData    )
</code></pre>

<pre><code class="r"># summary(Tree1)
plot(Tree1)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-10"/></p>

<pre><code class="r"># text(Tree1, pretty=0)
</code></pre>

<pre><code class="r">train_predict &lt;- predict(Tree1, trainData, type=&quot;response&quot;)
</code></pre>

<h2>in-sample confusion matrix</h2>

<pre><code class="r">table(train_predict&gt;0.5,trainData$high)
</code></pre>

<pre><code>##        
##            0    1
##   FALSE 1699  428
</code></pre>

<pre><code class="r">mean( (train_predict&gt;0.5) != trainData$high )*100
</code></pre>

<pre><code>## [1] 20.12224
</code></pre>

<pre><code class="r">test_predict &lt;- predict(Tree1, testData, type=&quot;response&quot;)
table(test_predict&gt;0.5,testData$high)
</code></pre>

<pre><code>##        
##           0   1
##   FALSE 727 156
</code></pre>

<pre><code class="r">mean( (test_predict&gt;0.5) != testData$high )*100
</code></pre>

<pre><code>## [1] 17.66704
</code></pre>

<h2>Causal Forest</h2>

<p>Generate feature data: \( X \sim \mathcal{N}(0, I_{p\times p}) \)</p>

<pre><code class="r">n = 2000; p = 10
X = matrix(rnorm(n*p), n, p)
out_len = 101
X.test = matrix(0, out_len , p)
X.test[,1] = seq(-2, 2, length.out = out_len )
</code></pre>

<p>Then we simulate the treatement variable, with propensity score \( p(X) = 0.5 \), and the outcome variable
\[ Y = \tau(X) D + X_2 + X_3 \wedge 0 + \varepsilon, \quad \varepsilon \sim \mathcal{N}(0,1), \]
\[  \tau(X) = X_1 \vee 0  \]</p>

<pre><code class="r"># Perform treatment effect estimation.
D = rbinom(n, 1, 0.5)
Y = pmax(X[,1], 0) * D + X[,2] + pmin(X[,3], 0) + rnorm(n)
dataTrain &lt;- as.data.frame(cbind(X,Y,D))

formula1 = paste( paste(colnames(dataTrain)[11], &quot;~ &quot;),paste(colnames(dataTrain)[1:10],collapse=&quot;+&quot;))
# tau.forest = causalForest(formula1, data=as.matrix(dataTrain), treatment = dataTrain$D,
#                             split.Rule=&quot;CT&quot;, split.Honest=T,  split.Bucket=F, bucketNum = 5,
#                             bucketMax = 100, cv.option=&quot;CT&quot;, cv.Honest=T, minsize = 2L, 
#                             split.alpha = 0.5, cv.alpha = 0.5,
#                             sample.size.total = floor(nrow(dataTrain) / 2), sample.size.train.frac = .5,
#                             mtry = ceiling(ncol(dataTrain)/3), nodesize = 3, num.trees= 5,ncolx=p,ncov_sample=p) 


ind &lt;- sample(1:n,floor(n/2),replace=F)
# honestTree &lt;- honest.causalTree(formula1, data=dataTrain[ind ,], treatment = dataTrain$D[ind ], 
#                                 est_data = dataTrain[-ind, ], 
#                                 est_treatment =  dataTrain$D[-ind ], 
#                                 split.Rule = &quot;CT&quot;, split.Honest = T, 
#                                 HonestSampleSize = nrow(dataTrain[-ind, ]), 
#                                 split.Bucket = T, cv.option = &quot;CT&quot;)
# 
#  honestTree$cptable
</code></pre>

<pre><code class="r"># opcp &lt;-  honestTree$cptable[,1][which.min(honestTree$cptable[,4])]
# opTree &lt;- prune(honestTree, opcp)
</code></pre>

<pre><code class="r"># rpart.plot(opTree)
</code></pre>

<pre><code class="r"># out &lt;- matrix(0,1,out_len )
# #### Forest
# s=floor(0.7*n)
# ntree=300
# 
# for(b in 1:ntree){
#   ind &lt;- sample(1:n,s,replace=F)
#   dataTrain &lt;- as.data.frame(cbind(X,Y,D))[ind,]
#   ind &lt;- sample(1:s,floor(s/2),replace=F)
#   honestTree &lt;- honest.causalTree(formula1, data=dataTrain[ind ,], treatment = dataTrain$D[ind ], 
#                                   est_data = dataTrain[-ind, ], 
#                                   est_treatment =  dataTrain$D[-ind ], 
#                                   split.Rule = &quot;CT&quot;, split.Honest = T, 
#                                   HonestSampleSize = nrow(dataTrain[-ind, ]), 
#                                   split.Bucket = T, cv.option = &quot;CT&quot;)
#   opcp &lt;-  honestTree$cptable[,1][which.min(honestTree$cptable[,4])]
#   opTree &lt;- prune(honestTree, opcp)
# out &lt;- out + predict(opTree, newdata=as.data.frame(X.test))
# }
# out &lt;- out /ntree
</code></pre>

<pre><code class="r"># plot(X.test[,1],out, ylim = range(out, 0, 2), xlab = &quot;x&quot;, ylab = &quot;tau&quot;, type = &quot;l&quot;)
# lines(X.test[,1], pmax(0, X.test[,1]), col = 2, lty = 2)
</code></pre>

<pre><code class="r">library(grf)
# cfpredtest &lt;- predict(cf, newdata=dataTest, type=&quot;vector&quot;)
tau.forest_2 = causal_forest(X, Y, D, precompute.nuisance = FALSE)
tau.hat_2 = predict(tau.forest_2, X.test)

tau.forest = causal_forest(X, Y, D)
tau.hat = predict(tau.forest, X.test)
variable_importance(tau.forest)
</code></pre>

<pre><code>##             [,1]
##  [1,] 0.70329348
##  [2,] 0.02798928
##  [3,] 0.02597512
##  [4,] 0.03096732
##  [5,] 0.02857355
##  [6,] 0.04540747
##  [7,] 0.04276017
##  [8,] 0.04374960
##  [9,] 0.02601756
## [10,] 0.02526645
</code></pre>

<p>Estimate the conditional average treatment effect on the full sample (CATE).</p>

<pre><code class="r">plot(X.test[,1], tau.hat$predictions, ylim = range(tau.hat$predictions, 0, 2), xlab = &quot;x&quot;, ylab = &quot;tau&quot;, type = &quot;l&quot;)
lines(X.test[,1], tau.hat_2$predictions, col = 4, lty = 2)
lines(X.test[,1], pmax(0, X.test[,1]), col = 2, lty = 2)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-21"/></p>

<pre><code class="r"># Estimate the conditional average treatment effect on the full sample (CATE).
estimate_average_effect(tau.forest, target.sample = &quot;all&quot;)
</code></pre>

<pre><code>## Error in estimate_average_effect(tau.forest, target.sample = &quot;all&quot;): impossible de trouver la fonction &quot;estimate_average_effect&quot;
</code></pre>

<pre><code class="r"># Estimate the conditional average treatment effect on the treated sample (CATT).
# Here, we don&#39;t expect much difference between the CATE and the CATT, since
# treatment assignment was randomized.
estimate_average_effect(tau.forest, target.sample = &quot;treated&quot;)
</code></pre>

<pre><code>## Error in estimate_average_effect(tau.forest, target.sample = &quot;treated&quot;): impossible de trouver la fonction &quot;estimate_average_effect&quot;
</code></pre>

<pre><code class="r"># Add confidence intervals for heterogeneous treatment effects
tau.forest = causal_forest(X, Y, D, num.trees = 4000)
tau.hat = predict(tau.forest, X.test, estimate.variance = TRUE)
sigma.hat = sqrt(tau.hat$variance.estimates)
</code></pre>

<pre><code class="r">plot(X.test[,1], tau.hat$predictions, ylim = range(tau.hat$predictions + 1.96 * sigma.hat, tau.hat$predictions - 1.96 * sigma.hat, 0, 2), xlab = &quot;x&quot;, ylab = &quot;tau&quot;, type = &quot;l&quot;)
lines(X.test[,1], tau.hat$predictions + 1.96 * sigma.hat, col = 1, lty = 2)
lines(X.test[,1], tau.hat$predictions - 1.96 * sigma.hat, col = 1, lty = 2)
lines(X.test[,1], pmax(0, X.test[,1]), col = 2, lty = 1)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-23"/></p>

<p>Add confidence intervals for heterogeneous treatment effects; growing more trees is now recommended.</p>

<pre><code class="r">tau.forest = causal_forest(X, Y, D, num.trees = 4000)
tau.hat = predict(tau.forest, X.test, estimate.variance = TRUE)
sigma.hat = sqrt(tau.hat$variance.estimates)
</code></pre>

<pre><code class="r">plot(X.test[,1], tau.hat$predictions, ylim = range(tau.hat$predictions +
            1.96 * sigma.hat, tau.hat$predictions - 1.96 * sigma.hat, 0, 2), 
     xlab = &quot;x&quot;, ylab = &quot;tau&quot;, type = &quot;l&quot;)
lines(X.test[,1], tau.hat$predictions + 1.96 * sigma.hat, col = 1, lty = 2)
lines(X.test[,1], tau.hat$predictions - 1.96 * sigma.hat, col = 1, lty = 2)
lines(X.test[,1], pmax(0, X.test[,1]), col = 2, lty = 1)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-25"/></p>

<h4>Another example</h4>

<h2>Case 1: without confounding factoers (p(x)=0)</h2>

<p>Generate data: \( X \sim \mathcal{N}(0, I_{d\times d}) \), treatement variable, with propensity score \( p(X) = 0.5 \), and the outcome variable
\[ Y = \tau(X) (D-0.5) + \varepsilon, \quad \varepsilon \sim \mathcal{N}(0,1), \]
with \[ \tau(X) = \zeta(X_1) \zeta(X_2),  \quad \zeta(x) = 1 + \dfrac{1}{1+e^{-20(x-1/3)}} . \]</p>

<pre><code class="r">### Without confounding factors (p(x) =constant)

# Generate data.
n = 10000; p = 3
X = matrix(runif(n*p), n, p)
X.test =matrix(runif(n*p), n, p)
# Perform treatment effect estimation.
D = rbinom(n, 1, 0.5)
zeta1 &lt;- function(x){
  return(1+ 1/(1+ exp(-20*(x-1/3))))
}
Y = (D-0.5)*(zeta1(X[,1]) *zeta1(X[,2])) + rnorm(n)
truth = (zeta1(X.test[,1]) *zeta1(X.test[,2]))

##### with CausalForest package
ntree=500
forest = causalForest(X, Y, D, num.trees = ntree, sample.size = n / 10)
</code></pre>

<pre><code>## [1] &quot;Building trees ...&quot;
## [1] &quot;Tree 1&quot;
## [1] &quot;Tree 2&quot;
## [1] &quot;Tree 3&quot;
## [1] &quot;Tree 4&quot;
## [1] &quot;Tree 5&quot;
## [1] &quot;Tree 6&quot;
## [1] &quot;Tree 7&quot;
## [1] &quot;Tree 8&quot;
## [1] &quot;Tree 9&quot;
## [1] &quot;Tree 10&quot;
## [1] &quot;Tree 11&quot;
## [1] &quot;Tree 12&quot;
## [1] &quot;Tree 13&quot;
## [1] &quot;Tree 14&quot;
## [1] &quot;Tree 15&quot;
## [1] &quot;Tree 16&quot;
## [1] &quot;Tree 17&quot;
## [1] &quot;Tree 18&quot;
## [1] &quot;Tree 19&quot;
## [1] &quot;Tree 20&quot;
## [1] &quot;Tree 21&quot;
## [1] &quot;Tree 22&quot;
## [1] &quot;Tree 23&quot;
## [1] &quot;Tree 24&quot;
## [1] &quot;Tree 25&quot;
## [1] &quot;Tree 26&quot;
## [1] &quot;Tree 27&quot;
## [1] &quot;Tree 28&quot;
## [1] &quot;Tree 29&quot;
## [1] &quot;Tree 30&quot;
## [1] &quot;Tree 31&quot;
## [1] &quot;Tree 32&quot;
## [1] &quot;Tree 33&quot;
## [1] &quot;Tree 34&quot;
## [1] &quot;Tree 35&quot;
## [1] &quot;Tree 36&quot;
## [1] &quot;Tree 37&quot;
## [1] &quot;Tree 38&quot;
## [1] &quot;Tree 39&quot;
## [1] &quot;Tree 40&quot;
## [1] &quot;Tree 41&quot;
## [1] &quot;Tree 42&quot;
## [1] &quot;Tree 43&quot;
## [1] &quot;Tree 44&quot;
## [1] &quot;Tree 45&quot;
## [1] &quot;Tree 46&quot;
## [1] &quot;Tree 47&quot;
## [1] &quot;Tree 48&quot;
## [1] &quot;Tree 49&quot;
## [1] &quot;Tree 50&quot;
## [1] &quot;Tree 51&quot;
## [1] &quot;Tree 52&quot;
## [1] &quot;Tree 53&quot;
## [1] &quot;Tree 54&quot;
## [1] &quot;Tree 55&quot;
## [1] &quot;Tree 56&quot;
## [1] &quot;Tree 57&quot;
## [1] &quot;Tree 58&quot;
## [1] &quot;Tree 59&quot;
## [1] &quot;Tree 60&quot;
## [1] &quot;Tree 61&quot;
## [1] &quot;Tree 62&quot;
## [1] &quot;Tree 63&quot;
## [1] &quot;Tree 64&quot;
## [1] &quot;Tree 65&quot;
## [1] &quot;Tree 66&quot;
## [1] &quot;Tree 67&quot;
## [1] &quot;Tree 68&quot;
## [1] &quot;Tree 69&quot;
## [1] &quot;Tree 70&quot;
## [1] &quot;Tree 71&quot;
## [1] &quot;Tree 72&quot;
## [1] &quot;Tree 73&quot;
## [1] &quot;Tree 74&quot;
## [1] &quot;Tree 75&quot;
## [1] &quot;Tree 76&quot;
## [1] &quot;Tree 77&quot;
## [1] &quot;Tree 78&quot;
## [1] &quot;Tree 79&quot;
## [1] &quot;Tree 80&quot;
## [1] &quot;Tree 81&quot;
## [1] &quot;Tree 82&quot;
## [1] &quot;Tree 83&quot;
## [1] &quot;Tree 84&quot;
## [1] &quot;Tree 85&quot;
## [1] &quot;Tree 86&quot;
## [1] &quot;Tree 87&quot;
## [1] &quot;Tree 88&quot;
## [1] &quot;Tree 89&quot;
## [1] &quot;Tree 90&quot;
## [1] &quot;Tree 91&quot;
## [1] &quot;Tree 92&quot;
## [1] &quot;Tree 93&quot;
## [1] &quot;Tree 94&quot;
## [1] &quot;Tree 95&quot;
## [1] &quot;Tree 96&quot;
## [1] &quot;Tree 97&quot;
## [1] &quot;Tree 98&quot;
## [1] &quot;Tree 99&quot;
## [1] &quot;Tree 100&quot;
## [1] &quot;Tree 101&quot;
## [1] &quot;Tree 102&quot;
## [1] &quot;Tree 103&quot;
## [1] &quot;Tree 104&quot;
## [1] &quot;Tree 105&quot;
## [1] &quot;Tree 106&quot;
## [1] &quot;Tree 107&quot;
## [1] &quot;Tree 108&quot;
## [1] &quot;Tree 109&quot;
## [1] &quot;Tree 110&quot;
## [1] &quot;Tree 111&quot;
## [1] &quot;Tree 112&quot;
## [1] &quot;Tree 113&quot;
## [1] &quot;Tree 114&quot;
## [1] &quot;Tree 115&quot;
## [1] &quot;Tree 116&quot;
## [1] &quot;Tree 117&quot;
## [1] &quot;Tree 118&quot;
## [1] &quot;Tree 119&quot;
## [1] &quot;Tree 120&quot;
## [1] &quot;Tree 121&quot;
## [1] &quot;Tree 122&quot;
## [1] &quot;Tree 123&quot;
## [1] &quot;Tree 124&quot;
## [1] &quot;Tree 125&quot;
## [1] &quot;Tree 126&quot;
## [1] &quot;Tree 127&quot;
## [1] &quot;Tree 128&quot;
## [1] &quot;Tree 129&quot;
## [1] &quot;Tree 130&quot;
## [1] &quot;Tree 131&quot;
## [1] &quot;Tree 132&quot;
## [1] &quot;Tree 133&quot;
## [1] &quot;Tree 134&quot;
## [1] &quot;Tree 135&quot;
## [1] &quot;Tree 136&quot;
## [1] &quot;Tree 137&quot;
## [1] &quot;Tree 138&quot;
## [1] &quot;Tree 139&quot;
## [1] &quot;Tree 140&quot;
## [1] &quot;Tree 141&quot;
## [1] &quot;Tree 142&quot;
## [1] &quot;Tree 143&quot;
## [1] &quot;Tree 144&quot;
## [1] &quot;Tree 145&quot;
## [1] &quot;Tree 146&quot;
## [1] &quot;Tree 147&quot;
## [1] &quot;Tree 148&quot;
## [1] &quot;Tree 149&quot;
## [1] &quot;Tree 150&quot;
## [1] &quot;Tree 151&quot;
## [1] &quot;Tree 152&quot;
## [1] &quot;Tree 153&quot;
## [1] &quot;Tree 154&quot;
## [1] &quot;Tree 155&quot;
## [1] &quot;Tree 156&quot;
## [1] &quot;Tree 157&quot;
## [1] &quot;Tree 158&quot;
## [1] &quot;Tree 159&quot;
## [1] &quot;Tree 160&quot;
## [1] &quot;Tree 161&quot;
## [1] &quot;Tree 162&quot;
## [1] &quot;Tree 163&quot;
## [1] &quot;Tree 164&quot;
## [1] &quot;Tree 165&quot;
## [1] &quot;Tree 166&quot;
## [1] &quot;Tree 167&quot;
## [1] &quot;Tree 168&quot;
## [1] &quot;Tree 169&quot;
## [1] &quot;Tree 170&quot;
## [1] &quot;Tree 171&quot;
## [1] &quot;Tree 172&quot;
## [1] &quot;Tree 173&quot;
## [1] &quot;Tree 174&quot;
## [1] &quot;Tree 175&quot;
## [1] &quot;Tree 176&quot;
## [1] &quot;Tree 177&quot;
## [1] &quot;Tree 178&quot;
## [1] &quot;Tree 179&quot;
## [1] &quot;Tree 180&quot;
## [1] &quot;Tree 181&quot;
## [1] &quot;Tree 182&quot;
## [1] &quot;Tree 183&quot;
## [1] &quot;Tree 184&quot;
## [1] &quot;Tree 185&quot;
## [1] &quot;Tree 186&quot;
## [1] &quot;Tree 187&quot;
## [1] &quot;Tree 188&quot;
## [1] &quot;Tree 189&quot;
## [1] &quot;Tree 190&quot;
## [1] &quot;Tree 191&quot;
## [1] &quot;Tree 192&quot;
## [1] &quot;Tree 193&quot;
## [1] &quot;Tree 194&quot;
## [1] &quot;Tree 195&quot;
## [1] &quot;Tree 196&quot;
## [1] &quot;Tree 197&quot;
## [1] &quot;Tree 198&quot;
## [1] &quot;Tree 199&quot;
## [1] &quot;Tree 200&quot;
## [1] &quot;Tree 201&quot;
## [1] &quot;Tree 202&quot;
## [1] &quot;Tree 203&quot;
## [1] &quot;Tree 204&quot;
## [1] &quot;Tree 205&quot;
## [1] &quot;Tree 206&quot;
## [1] &quot;Tree 207&quot;
## [1] &quot;Tree 208&quot;
## [1] &quot;Tree 209&quot;
## [1] &quot;Tree 210&quot;
## [1] &quot;Tree 211&quot;
## [1] &quot;Tree 212&quot;
## [1] &quot;Tree 213&quot;
## [1] &quot;Tree 214&quot;
## [1] &quot;Tree 215&quot;
## [1] &quot;Tree 216&quot;
## [1] &quot;Tree 217&quot;
## [1] &quot;Tree 218&quot;
## [1] &quot;Tree 219&quot;
## [1] &quot;Tree 220&quot;
## [1] &quot;Tree 221&quot;
## [1] &quot;Tree 222&quot;
## [1] &quot;Tree 223&quot;
## [1] &quot;Tree 224&quot;
## [1] &quot;Tree 225&quot;
## [1] &quot;Tree 226&quot;
## [1] &quot;Tree 227&quot;
## [1] &quot;Tree 228&quot;
## [1] &quot;Tree 229&quot;
## [1] &quot;Tree 230&quot;
## [1] &quot;Tree 231&quot;
## [1] &quot;Tree 232&quot;
## [1] &quot;Tree 233&quot;
## [1] &quot;Tree 234&quot;
## [1] &quot;Tree 235&quot;
## [1] &quot;Tree 236&quot;
## [1] &quot;Tree 237&quot;
## [1] &quot;Tree 238&quot;
## [1] &quot;Tree 239&quot;
## [1] &quot;Tree 240&quot;
## [1] &quot;Tree 241&quot;
## [1] &quot;Tree 242&quot;
## [1] &quot;Tree 243&quot;
## [1] &quot;Tree 244&quot;
## [1] &quot;Tree 245&quot;
## [1] &quot;Tree 246&quot;
## [1] &quot;Tree 247&quot;
## [1] &quot;Tree 248&quot;
## [1] &quot;Tree 249&quot;
## [1] &quot;Tree 250&quot;
## [1] &quot;Tree 251&quot;
## [1] &quot;Tree 252&quot;
## [1] &quot;Tree 253&quot;
## [1] &quot;Tree 254&quot;
## [1] &quot;Tree 255&quot;
## [1] &quot;Tree 256&quot;
## [1] &quot;Tree 257&quot;
## [1] &quot;Tree 258&quot;
## [1] &quot;Tree 259&quot;
## [1] &quot;Tree 260&quot;
## [1] &quot;Tree 261&quot;
## [1] &quot;Tree 262&quot;
## [1] &quot;Tree 263&quot;
## [1] &quot;Tree 264&quot;
## [1] &quot;Tree 265&quot;
## [1] &quot;Tree 266&quot;
## [1] &quot;Tree 267&quot;
## [1] &quot;Tree 268&quot;
## [1] &quot;Tree 269&quot;
## [1] &quot;Tree 270&quot;
## [1] &quot;Tree 271&quot;
## [1] &quot;Tree 272&quot;
## [1] &quot;Tree 273&quot;
## [1] &quot;Tree 274&quot;
## [1] &quot;Tree 275&quot;
## [1] &quot;Tree 276&quot;
## [1] &quot;Tree 277&quot;
## [1] &quot;Tree 278&quot;
## [1] &quot;Tree 279&quot;
## [1] &quot;Tree 280&quot;
## [1] &quot;Tree 281&quot;
## [1] &quot;Tree 282&quot;
## [1] &quot;Tree 283&quot;
## [1] &quot;Tree 284&quot;
## [1] &quot;Tree 285&quot;
## [1] &quot;Tree 286&quot;
## [1] &quot;Tree 287&quot;
## [1] &quot;Tree 288&quot;
## [1] &quot;Tree 289&quot;
## [1] &quot;Tree 290&quot;
## [1] &quot;Tree 291&quot;
## [1] &quot;Tree 292&quot;
## [1] &quot;Tree 293&quot;
## [1] &quot;Tree 294&quot;
## [1] &quot;Tree 295&quot;
## [1] &quot;Tree 296&quot;
## [1] &quot;Tree 297&quot;
## [1] &quot;Tree 298&quot;
## [1] &quot;Tree 299&quot;
## [1] &quot;Tree 300&quot;
## [1] &quot;Tree 301&quot;
## [1] &quot;Tree 302&quot;
## [1] &quot;Tree 303&quot;
## [1] &quot;Tree 304&quot;
## [1] &quot;Tree 305&quot;
## [1] &quot;Tree 306&quot;
## [1] &quot;Tree 307&quot;
## [1] &quot;Tree 308&quot;
## [1] &quot;Tree 309&quot;
## [1] &quot;Tree 310&quot;
## [1] &quot;Tree 311&quot;
## [1] &quot;Tree 312&quot;
## [1] &quot;Tree 313&quot;
## [1] &quot;Tree 314&quot;
## [1] &quot;Tree 315&quot;
## [1] &quot;Tree 316&quot;
## [1] &quot;Tree 317&quot;
## [1] &quot;Tree 318&quot;
## [1] &quot;Tree 319&quot;
## [1] &quot;Tree 320&quot;
## [1] &quot;Tree 321&quot;
## [1] &quot;Tree 322&quot;
## [1] &quot;Tree 323&quot;
## [1] &quot;Tree 324&quot;
## [1] &quot;Tree 325&quot;
## [1] &quot;Tree 326&quot;
## [1] &quot;Tree 327&quot;
## [1] &quot;Tree 328&quot;
## [1] &quot;Tree 329&quot;
## [1] &quot;Tree 330&quot;
## [1] &quot;Tree 331&quot;
## [1] &quot;Tree 332&quot;
## [1] &quot;Tree 333&quot;
## [1] &quot;Tree 334&quot;
## [1] &quot;Tree 335&quot;
## [1] &quot;Tree 336&quot;
## [1] &quot;Tree 337&quot;
## [1] &quot;Tree 338&quot;
## [1] &quot;Tree 339&quot;
## [1] &quot;Tree 340&quot;
## [1] &quot;Tree 341&quot;
## [1] &quot;Tree 342&quot;
## [1] &quot;Tree 343&quot;
## [1] &quot;Tree 344&quot;
## [1] &quot;Tree 345&quot;
## [1] &quot;Tree 346&quot;
## [1] &quot;Tree 347&quot;
## [1] &quot;Tree 348&quot;
## [1] &quot;Tree 349&quot;
## [1] &quot;Tree 350&quot;
## [1] &quot;Tree 351&quot;
## [1] &quot;Tree 352&quot;
## [1] &quot;Tree 353&quot;
## [1] &quot;Tree 354&quot;
## [1] &quot;Tree 355&quot;
## [1] &quot;Tree 356&quot;
## [1] &quot;Tree 357&quot;
## [1] &quot;Tree 358&quot;
## [1] &quot;Tree 359&quot;
## [1] &quot;Tree 360&quot;
## [1] &quot;Tree 361&quot;
## [1] &quot;Tree 362&quot;
## [1] &quot;Tree 363&quot;
## [1] &quot;Tree 364&quot;
## [1] &quot;Tree 365&quot;
## [1] &quot;Tree 366&quot;
## [1] &quot;Tree 367&quot;
## [1] &quot;Tree 368&quot;
## [1] &quot;Tree 369&quot;
## [1] &quot;Tree 370&quot;
## [1] &quot;Tree 371&quot;
## [1] &quot;Tree 372&quot;
## [1] &quot;Tree 373&quot;
## [1] &quot;Tree 374&quot;
## [1] &quot;Tree 375&quot;
## [1] &quot;Tree 376&quot;
## [1] &quot;Tree 377&quot;
## [1] &quot;Tree 378&quot;
## [1] &quot;Tree 379&quot;
## [1] &quot;Tree 380&quot;
## [1] &quot;Tree 381&quot;
## [1] &quot;Tree 382&quot;
## [1] &quot;Tree 383&quot;
## [1] &quot;Tree 384&quot;
## [1] &quot;Tree 385&quot;
## [1] &quot;Tree 386&quot;
## [1] &quot;Tree 387&quot;
## [1] &quot;Tree 388&quot;
## [1] &quot;Tree 389&quot;
## [1] &quot;Tree 390&quot;
## [1] &quot;Tree 391&quot;
## [1] &quot;Tree 392&quot;
## [1] &quot;Tree 393&quot;
## [1] &quot;Tree 394&quot;
## [1] &quot;Tree 395&quot;
## [1] &quot;Tree 396&quot;
## [1] &quot;Tree 397&quot;
## [1] &quot;Tree 398&quot;
## [1] &quot;Tree 399&quot;
## [1] &quot;Tree 400&quot;
## [1] &quot;Tree 401&quot;
## [1] &quot;Tree 402&quot;
## [1] &quot;Tree 403&quot;
## [1] &quot;Tree 404&quot;
## [1] &quot;Tree 405&quot;
## [1] &quot;Tree 406&quot;
## [1] &quot;Tree 407&quot;
## [1] &quot;Tree 408&quot;
## [1] &quot;Tree 409&quot;
## [1] &quot;Tree 410&quot;
## [1] &quot;Tree 411&quot;
## [1] &quot;Tree 412&quot;
## [1] &quot;Tree 413&quot;
## [1] &quot;Tree 414&quot;
## [1] &quot;Tree 415&quot;
## [1] &quot;Tree 416&quot;
## [1] &quot;Tree 417&quot;
## [1] &quot;Tree 418&quot;
## [1] &quot;Tree 419&quot;
## [1] &quot;Tree 420&quot;
## [1] &quot;Tree 421&quot;
## [1] &quot;Tree 422&quot;
## [1] &quot;Tree 423&quot;
## [1] &quot;Tree 424&quot;
## [1] &quot;Tree 425&quot;
## [1] &quot;Tree 426&quot;
## [1] &quot;Tree 427&quot;
## [1] &quot;Tree 428&quot;
## [1] &quot;Tree 429&quot;
## [1] &quot;Tree 430&quot;
## [1] &quot;Tree 431&quot;
## [1] &quot;Tree 432&quot;
## [1] &quot;Tree 433&quot;
## [1] &quot;Tree 434&quot;
## [1] &quot;Tree 435&quot;
## [1] &quot;Tree 436&quot;
## [1] &quot;Tree 437&quot;
## [1] &quot;Tree 438&quot;
## [1] &quot;Tree 439&quot;
## [1] &quot;Tree 440&quot;
## [1] &quot;Tree 441&quot;
## [1] &quot;Tree 442&quot;
## [1] &quot;Tree 443&quot;
## [1] &quot;Tree 444&quot;
## [1] &quot;Tree 445&quot;
## [1] &quot;Tree 446&quot;
## [1] &quot;Tree 447&quot;
## [1] &quot;Tree 448&quot;
## [1] &quot;Tree 449&quot;
## [1] &quot;Tree 450&quot;
## [1] &quot;Tree 451&quot;
## [1] &quot;Tree 452&quot;
## [1] &quot;Tree 453&quot;
## [1] &quot;Tree 454&quot;
## [1] &quot;Tree 455&quot;
## [1] &quot;Tree 456&quot;
## [1] &quot;Tree 457&quot;
## [1] &quot;Tree 458&quot;
## [1] &quot;Tree 459&quot;
## [1] &quot;Tree 460&quot;
## [1] &quot;Tree 461&quot;
## [1] &quot;Tree 462&quot;
## [1] &quot;Tree 463&quot;
## [1] &quot;Tree 464&quot;
## [1] &quot;Tree 465&quot;
## [1] &quot;Tree 466&quot;
## [1] &quot;Tree 467&quot;
## [1] &quot;Tree 468&quot;
## [1] &quot;Tree 469&quot;
## [1] &quot;Tree 470&quot;
## [1] &quot;Tree 471&quot;
## [1] &quot;Tree 472&quot;
## [1] &quot;Tree 473&quot;
## [1] &quot;Tree 474&quot;
## [1] &quot;Tree 475&quot;
## [1] &quot;Tree 476&quot;
## [1] &quot;Tree 477&quot;
## [1] &quot;Tree 478&quot;
## [1] &quot;Tree 479&quot;
## [1] &quot;Tree 480&quot;
## [1] &quot;Tree 481&quot;
## [1] &quot;Tree 482&quot;
## [1] &quot;Tree 483&quot;
## [1] &quot;Tree 484&quot;
## [1] &quot;Tree 485&quot;
## [1] &quot;Tree 486&quot;
## [1] &quot;Tree 487&quot;
## [1] &quot;Tree 488&quot;
## [1] &quot;Tree 489&quot;
## [1] &quot;Tree 490&quot;
## [1] &quot;Tree 491&quot;
## [1] &quot;Tree 492&quot;
## [1] &quot;Tree 493&quot;
## [1] &quot;Tree 494&quot;
## [1] &quot;Tree 495&quot;
## [1] &quot;Tree 496&quot;
## [1] &quot;Tree 497&quot;
## [1] &quot;Tree 498&quot;
## [1] &quot;Tree 499&quot;
## [1] &quot;Tree 500&quot;
</code></pre>

<pre><code class="r">tauhat.rf &lt;- predict(forest, X.test)
</code></pre>

<p>Estimation, with \( s=n/2 \) and \( B=2000 \).</p>

<pre><code class="r"># #### with the grf package
# tau.forest = causal_forest(X, Y, D, sample.fraction = 0.5,num.tree = 2000  )
# # tau.knn = iv.series(X, Y, W,Z=NULL  )
# tau.hat = predict(tau.forest, X.test)

# ##### kNN comparison
library(FNN)
# neighbors = get.knnx(X,X.test, k=100)$nn.index

kk = c(seq(3, 99, by = 3))
knn.mses = sapply(kk, function(k) {
  neighbors = get.knnx(X,X.test, k=k)$nn.index
  tauhat =  apply(neighbors, 1, function(nn) {
    Yp = Y[nn]
    Dp = D[nn]
    y.hat = mean(Yp[Dp==1]) -  mean(Yp[Dp==0]) 
  })
  mean((truth - tauhat)^2)
})

print(knn.mses)
</code></pre>

<pre><code>##  [1]        NaN        NaN        NaN        NaN        NaN        NaN
##  [7] 0.20683755 0.17826340 0.15810849 0.14338918 0.13156713 0.12159858
## [13] 0.11304527 0.10603162 0.09910287 0.09304895 0.08753174 0.08385623
## [19] 0.07975805 0.07662838 0.07330064 0.07021351 0.06729220 0.06468396
## [25] 0.06243702 0.06042775 0.05878345 0.05716724 0.05552211 0.05395682
## [31] 0.05276476 0.05170495 0.05041966
</code></pre>

<p>Comparison with k-nearest neighbors: 
\[ \widehat{\tau}_{kNN} = \dfrac{1}{k}\sum_{i \in S_1(x)}Y_i - \dfrac{1}{k}\sum_{i \in S_0(x)}Y_i \]</p>

<pre><code class="r">#### compute for the optimum
k.opt = kk[which.min(knn.mses)]
neighbors = get.knnx(X,X.test, k=k.opt)$nn.index
tau.hat.k &lt;-  apply(neighbors, 1, function(nn) {
  Yp = Y[nn]
  Dp = D[nn]
  y.hat = mean(Yp[Dp==1]) -  mean(Yp[Dp==0]) 
})


library(RColorBrewer)
library(Hmisc)
</code></pre>

<pre><code>## Loading required package: lattice
</code></pre>

<pre><code>## Loading required package: survival
</code></pre>

<pre><code>## Loading required package: Formula
</code></pre>

<pre><code>## Loading required package: ggplot2
</code></pre>

<pre><code>## 
## Attaching package: &#39;Hmisc&#39;
</code></pre>

<pre><code>## The following object is masked from &#39;package:randomForestCI&#39;:
## 
##     gbayes
</code></pre>

<pre><code>## The following objects are masked from &#39;package:base&#39;:
## 
##     format.pval, units
</code></pre>

<pre><code class="r">library(mgcv)
</code></pre>

<pre><code>## Loading required package: nlme
</code></pre>

<pre><code>## 
## Attaching package: &#39;nlme&#39;
</code></pre>

<pre><code>## The following object is masked from &#39;package:Ecdat&#39;:
## 
##     Gasoline
</code></pre>

<pre><code>## This is mgcv 1.8-23. For overview type &#39;help(&quot;mgcv-package&quot;)&#39;.
</code></pre>

<pre><code class="r">library(ggplot2)
x &lt;- seq(-1, 1, length=100)
y &lt;- seq(-1, 1, length=100)
xy &lt;- expand.grid(x=x, y=y)
# xy &lt;- cbind(xy , matrix(0,100,1))
xy &lt;- cbind(xy , matrix(0,100,1), matrix(0,100,1), matrix(0,100,1), matrix(0,100,1))

k &lt;- 10
my.cols &lt;- rev(brewer.pal(k, &quot;RdYlBu&quot;))

minp = min(truth, tauhat.rf, tau.hat.k)
maxp = max(truth, tauhat.rf, tau.hat.k)
rngp = maxp - minp

ncol = 100

true.scl = pmax(ceiling(ncol * (truth - minp) / rngp), 1)
rf.scl = pmax(ceiling(ncol * (tauhat.rf - minp) / rngp), 1)
knn.scl = pmax(ceiling(ncol * (tau.hat.k - minp) / rngp), 1)
hc = heat.colors(ncol)
</code></pre>

<p>The True Treatment effect</p>

<pre><code class="r">plot(X.test[,1], X.test[,2], pch = 16, col = hc[true.scl], xlab = &quot;&quot;, ylab = &quot;&quot;,main = &quot;True&quot;)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-29"/></p>

<p>The treatment effect estimated via random forest</p>

<pre><code class="r">plot(X.test[,1], X.test[,2], pch = 16, col = hc[rf.scl], xlab = &quot;&quot;, ylab = &quot;&quot;,main = &quot;Causal Forest&quot;)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-30"/></p>

<p>The treatment effect estimated via kNN</p>

<pre><code class="r">plot(X.test[,1], X.test[,2], pch = 16, col = hc[knn.scl], xlab = &quot;&quot;, ylab = &quot;&quot;,main = &quot;KNN&quot;)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-31"/></p>

<pre><code>

```r
neighbors = get.knnx(X,xy, k=k.opt)$nn.index
</code></pre>

<pre><code>## Error in get.knnx(X, xy, k = k.opt): Number of columns must be same!.
</code></pre>

<pre><code class="r">tau.hat.k &lt;-  apply(neighbors, 1, function(nn) {
  Yp = Y[nn]
  Dp = D[nn]
  y.hat = mean(Yp[Dp==1]) -  mean(Yp[Dp==0]) 
})
# tau.hat = predict(tau.forest, xy)
colnames(xy) &lt;- colnames(X.test)
tau.hat =predict(forest,xy)
z &lt;- matrix(tau.hat, length(x), length(y))
z_k &lt;- matrix(tau.hat.k, length(x), length(y))
z1 &lt;- matrix(zeta1(xy[,1]) *zeta1(xy[,2]), length(x), length(y))

# z1_cut &lt;-cut(tau.hat$predictions, quantile(tau.hat$predictions,seq(0,1, length.out=k))+seq(0,0.001, length.out=k)   )
</code></pre>

<p>The treatment effect estimated via random forests</p>

<pre><code class="r">z1_cut &lt;-cut(tau.hat, quantile(tau.hat,seq(0,1, length.out=k))+seq(0,0.001, length.out=k)   )
plot(xy[,1],xy[,2], col=my.cols[z1_cut], pch = 15, main=&quot;Causal Forest&quot;)
contour(x,y,z1, drawlabels=FALSE, nlevels=k, lwd=2, add=TRUE)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-33"/></p>

<p>The treatment effect estimated via kNN</p>

<pre><code class="r">z1_cut &lt;-cut(tau.hat.k, quantile(tau.hat.k,seq(0,1, length.out=k))+seq(0,0.001, length.out=k)   )
plot(xy[,1],xy[,2], col=my.cols[z1_cut], pch = 15, main=&quot;KNN&quot;)
contour(x,y,z1, drawlabels=FALSE, nlevels=k, lwd=2, add=TRUE)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-34"/></p>

<p>The true treatment effect</p>

<pre><code class="r">truth &lt;- (zeta1(xy[,1]) *zeta1(xy[,2]))
z1_cut &lt;-cut(truth, quantile(truth,seq(0,1, length.out=k))+seq(0,0.001, length.out=k)   )
plot(xy[,1],xy[,2], col=my.cols[z1_cut], pch = 15, main=&quot;True&quot;)
contour(x,y,z1, drawlabels=FALSE, nlevels=k, lwd=2, add=TRUE)
</code></pre>

<p><img src="" alt="plot of chunk unnamed-chunk-35"/></p>

<p><img src="figures/im1.png" alt=""/></p>

<p><img src="figures/im2.png" alt=""/></p>

<h5>With no treatment effect but selection on the observables (A)</h5>

<pre><code class="r">tau =0 
p=3
X = matrix(runif(n * p, 0, 1), n, p) # features
propensity = (1 + dbeta(X[,3], 2, 4)) / 4
mu = 2*X[,3] - 1
D = rbinom(n, 1, propensity)
Y = mu + (D -0.5)* tau + rnorm(n)

tree_mult = 1000
X.test =matrix(runif(n*p), n, p)

forest = propensityForest(X, Y, D, num.trees = tree_mult, sample.size = n^(0.8), nodesize = 1)
</code></pre>

<pre><code>## [1] &quot;Building trees ...&quot;
## [1] &quot;Tree 1&quot;
## [1] &quot;Tree 2&quot;
## [1] &quot;Tree 3&quot;
## [1] &quot;Tree 4&quot;
## [1] &quot;Tree 5&quot;
## [1] &quot;Tree 6&quot;
## [1] &quot;Tree 7&quot;
## [1] &quot;Tree 8&quot;
## [1] &quot;Tree 9&quot;
## [1] &quot;Tree 10&quot;
## [1] &quot;Tree 11&quot;
## [1] &quot;Tree 12&quot;
## [1] &quot;Tree 13&quot;
## [1] &quot;Tree 14&quot;
## [1] &quot;Tree 15&quot;
## [1] &quot;Tree 16&quot;
## [1] &quot;Tree 17&quot;
## [1] &quot;Tree 18&quot;
## [1] &quot;Tree 19&quot;
## [1] &quot;Tree 20&quot;
## [1] &quot;Tree 21&quot;
## [1] &quot;Tree 22&quot;
## [1] &quot;Tree 23&quot;
## [1] &quot;Tree 24&quot;
## [1] &quot;Tree 25&quot;
## [1] &quot;Tree 26&quot;
## [1] &quot;Tree 27&quot;
## [1] &quot;Tree 28&quot;
## [1] &quot;Tree 29&quot;
## [1] &quot;Tree 30&quot;
## [1] &quot;Tree 31&quot;
## [1] &quot;Tree 32&quot;
## [1] &quot;Tree 33&quot;
## [1] &quot;Tree 34&quot;
## [1] &quot;Tree 35&quot;
## [1] &quot;Tree 36&quot;
## [1] &quot;Tree 37&quot;
## [1] &quot;Tree 38&quot;
## [1] &quot;Tree 39&quot;
## [1] &quot;Tree 40&quot;
## [1] &quot;Tree 41&quot;
## [1] &quot;Tree 42&quot;
## [1] &quot;Tree 43&quot;
## [1] &quot;Tree 44&quot;
## [1] &quot;Tree 45&quot;
## [1] &quot;Tree 46&quot;
## [1] &quot;Tree 47&quot;
## [1] &quot;Tree 48&quot;
## [1] &quot;Tree 49&quot;
## [1] &quot;Tree 50&quot;
## [1] &quot;Tree 51&quot;
## [1] &quot;Tree 52&quot;
## [1] &quot;Tree 53&quot;
## [1] &quot;Tree 54&quot;
## [1] &quot;Tree 55&quot;
## [1] &quot;Tree 56&quot;
## [1] &quot;Tree 57&quot;
## [1] &quot;Tree 58&quot;
## [1] &quot;Tree 59&quot;
## [1] &quot;Tree 60&quot;
## [1] &quot;Tree 61&quot;
## [1] &quot;Tree 62&quot;
## [1] &quot;Tree 63&quot;
## [1] &quot;Tree 64&quot;
## [1] &quot;Tree 65&quot;
## [1] &quot;Tree 66&quot;
## [1] &quot;Tree 67&quot;
## [1] &quot;Tree 68&quot;
## [1] &quot;Tree 69&quot;
## [1] &quot;Tree 70&quot;
## [1] &quot;Tree 71&quot;
## [1] &quot;Tree 72&quot;
## [1] &quot;Tree 73&quot;
## [1] &quot;Tree 74&quot;
## [1] &quot;Tree 75&quot;
## [1] &quot;Tree 76&quot;
## [1] &quot;Tree 77&quot;
## [1] &quot;Tree 78&quot;
## [1] &quot;Tree 79&quot;
## [1] &quot;Tree 80&quot;
## [1] &quot;Tree 81&quot;
## [1] &quot;Tree 82&quot;
## [1] &quot;Tree 83&quot;
## [1] &quot;Tree 84&quot;
## [1] &quot;Tree 85&quot;
## [1] &quot;Tree 86&quot;
## [1] &quot;Tree 87&quot;
## [1] &quot;Tree 88&quot;
## [1] &quot;Tree 89&quot;
## [1] &quot;Tree 90&quot;
## [1] &quot;Tree 91&quot;
## [1] &quot;Tree 92&quot;
## [1] &quot;Tree 93&quot;
## [1] &quot;Tree 94&quot;
## [1] &quot;Tree 95&quot;
## [1] &quot;Tree 96&quot;
## [1] &quot;Tree 97&quot;
## [1] &quot;Tree 98&quot;
## [1] &quot;Tree 99&quot;
## [1] &quot;Tree 100&quot;
## [1] &quot;Tree 101&quot;
## [1] &quot;Tree 102&quot;
## [1] &quot;Tree 103&quot;
## [1] &quot;Tree 104&quot;
## [1] &quot;Tree 105&quot;
## [1] &quot;Tree 106&quot;
## [1] &quot;Tree 107&quot;
## [1] &quot;Tree 108&quot;
## [1] &quot;Tree 109&quot;
## [1] &quot;Tree 110&quot;
## [1] &quot;Tree 111&quot;
## [1] &quot;Tree 112&quot;
## [1] &quot;Tree 113&quot;
## [1] &quot;Tree 114&quot;
## [1] &quot;Tree 115&quot;
## [1] &quot;Tree 116&quot;
## [1] &quot;Tree 117&quot;
## [1] &quot;Tree 118&quot;
## [1] &quot;Tree 119&quot;
## [1] &quot;Tree 120&quot;
## [1] &quot;Tree 121&quot;
## [1] &quot;Tree 122&quot;
## [1] &quot;Tree 123&quot;
## [1] &quot;Tree 124&quot;
## [1] &quot;Tree 125&quot;
## [1] &quot;Tree 126&quot;
## [1] &quot;Tree 127&quot;
## [1] &quot;Tree 128&quot;
## [1] &quot;Tree 129&quot;
## [1] &quot;Tree 130&quot;
## [1] &quot;Tree 131&quot;
## [1] &quot;Tree 132&quot;
## [1] &quot;Tree 133&quot;
## [1] &quot;Tree 134&quot;
## [1] &quot;Tree 135&quot;
## [1] &quot;Tree 136&quot;
## [1] &quot;Tree 137&quot;
## [1] &quot;Tree 138&quot;
## [1] &quot;Tree 139&quot;
## [1] &quot;Tree 140&quot;
## [1] &quot;Tree 141&quot;
## [1] &quot;Tree 142&quot;
## [1] &quot;Tree 143&quot;
## [1] &quot;Tree 144&quot;
## [1] &quot;Tree 145&quot;
## [1] &quot;Tree 146&quot;
## [1] &quot;Tree 147&quot;
## [1] &quot;Tree 148&quot;
## [1] &quot;Tree 149&quot;
## [1] &quot;Tree 150&quot;
## [1] &quot;Tree 151&quot;
## [1] &quot;Tree 152&quot;
## [1] &quot;Tree 153&quot;
## [1] &quot;Tree 154&quot;
## [1] &quot;Tree 155&quot;
## [1] &quot;Tree 156&quot;
## [1] &quot;Tree 157&quot;
## [1] &quot;Tree 158&quot;
## [1] &quot;Tree 159&quot;
## [1] &quot;Tree 160&quot;
## [1] &quot;Tree 161&quot;
## [1] &quot;Tree 162&quot;
## [1] &quot;Tree 163&quot;
## [1] &quot;Tree 164&quot;
## [1] &quot;Tree 165&quot;
## [1] &quot;Tree 166&quot;
## [1] &quot;Tree 167&quot;
## [1] &quot;Tree 168&quot;
## [1] &quot;Tree 169&quot;
## [1] &quot;Tree 170&quot;
## [1] &quot;Tree 171&quot;
## [1] &quot;Tree 172&quot;
## [1] &quot;Tree 173&quot;
## [1] &quot;Tree 174&quot;
## [1] &quot;Tree 175&quot;
## [1] &quot;Tree 176&quot;
## [1] &quot;Tree 177&quot;
## [1] &quot;Tree 178&quot;
## [1] &quot;Tree 179&quot;
## [1] &quot;Tree 180&quot;
## [1] &quot;Tree 181&quot;
## [1] &quot;Tree 182&quot;
## [1] &quot;Tree 183&quot;
## [1] &quot;Tree 184&quot;
## [1] &quot;Tree 185&quot;
## [1] &quot;Tree 186&quot;
## [1] &quot;Tree 187&quot;
## [1] &quot;Tree 188&quot;
## [1] &quot;Tree 189&quot;
## [1] &quot;Tree 190&quot;
## [1] &quot;Tree 191&quot;
## [1] &quot;Tree 192&quot;
## [1] &quot;Tree 193&quot;
## [1] &quot;Tree 194&quot;
## [1] &quot;Tree 195&quot;
## [1] &quot;Tree 196&quot;
## [1] &quot;Tree 197&quot;
## [1] &quot;Tree 198&quot;
## [1] &quot;Tree 199&quot;
## [1] &quot;Tree 200&quot;
## [1] &quot;Tree 201&quot;
## [1] &quot;Tree 202&quot;
## [1] &quot;Tree 203&quot;
## [1] &quot;Tree 204&quot;
## [1] &quot;Tree 205&quot;
## [1] &quot;Tree 206&quot;
## [1] &quot;Tree 207&quot;
## [1] &quot;Tree 208&quot;
## [1] &quot;Tree 209&quot;
## [1] &quot;Tree 210&quot;
## [1] &quot;Tree 211&quot;
## [1] &quot;Tree 212&quot;
## [1] &quot;Tree 213&quot;
## [1] &quot;Tree 214&quot;
## [1] &quot;Tree 215&quot;
## [1] &quot;Tree 216&quot;
## [1] &quot;Tree 217&quot;
## [1] &quot;Tree 218&quot;
## [1] &quot;Tree 219&quot;
## [1] &quot;Tree 220&quot;
## [1] &quot;Tree 221&quot;
## [1] &quot;Tree 222&quot;
## [1] &quot;Tree 223&quot;
## [1] &quot;Tree 224&quot;
## [1] &quot;Tree 225&quot;
## [1] &quot;Tree 226&quot;
## [1] &quot;Tree 227&quot;
## [1] &quot;Tree 228&quot;
## [1] &quot;Tree 229&quot;
## [1] &quot;Tree 230&quot;
## [1] &quot;Tree 231&quot;
## [1] &quot;Tree 232&quot;
## [1] &quot;Tree 233&quot;
## [1] &quot;Tree 234&quot;
## [1] &quot;Tree 235&quot;
## [1] &quot;Tree 236&quot;
## [1] &quot;Tree 237&quot;
## [1] &quot;Tree 238&quot;
## [1] &quot;Tree 239&quot;
## [1] &quot;Tree 240&quot;
## [1] &quot;Tree 241&quot;
## [1] &quot;Tree 242&quot;
## [1] &quot;Tree 243&quot;
## [1] &quot;Tree 244&quot;
## [1] &quot;Tree 245&quot;
## [1] &quot;Tree 246&quot;
## [1] &quot;Tree 247&quot;
## [1] &quot;Tree 248&quot;
## [1] &quot;Tree 249&quot;
## [1] &quot;Tree 250&quot;
## [1] &quot;Tree 251&quot;
## [1] &quot;Tree 252&quot;
## [1] &quot;Tree 253&quot;
## [1] &quot;Tree 254&quot;
## [1] &quot;Tree 255&quot;
## [1] &quot;Tree 256&quot;
## [1] &quot;Tree 257&quot;
## [1] &quot;Tree 258&quot;
## [1] &quot;Tree 259&quot;
## [1] &quot;Tree 260&quot;
## [1] &quot;Tree 261&quot;
## [1] &quot;Tree 262&quot;
## [1] &quot;Tree 263&quot;
## [1] &quot;Tree 264&quot;
## [1] &quot;Tree 265&quot;
## [1] &quot;Tree 266&quot;
## [1] &quot;Tree 267&quot;
## [1] &quot;Tree 268&quot;
## [1] &quot;Tree 269&quot;
## [1] &quot;Tree 270&quot;
## [1] &quot;Tree 271&quot;
## [1] &quot;Tree 272&quot;
## [1] &quot;Tree 273&quot;
## [1] &quot;Tree 274&quot;
## [1] &quot;Tree 275&quot;
## [1] &quot;Tree 276&quot;
## [1] &quot;Tree 277&quot;
## [1] &quot;Tree 278&quot;
## [1] &quot;Tree 279&quot;
## [1] &quot;Tree 280&quot;
## [1] &quot;Tree 281&quot;
## [1] &quot;Tree 282&quot;
## [1] &quot;Tree 283&quot;
## [1] &quot;Tree 284&quot;
## [1] &quot;Tree 285&quot;
## [1] &quot;Tree 286&quot;
## [1] &quot;Tree 287&quot;
## [1] &quot;Tree 288&quot;
## [1] &quot;Tree 289&quot;
## [1] &quot;Tree 290&quot;
## [1] &quot;Tree 291&quot;
## [1] &quot;Tree 292&quot;
## [1] &quot;Tree 293&quot;
## [1] &quot;Tree 294&quot;
## [1] &quot;Tree 295&quot;
## [1] &quot;Tree 296&quot;
## [1] &quot;Tree 297&quot;
## [1] &quot;Tree 298&quot;
## [1] &quot;Tree 299&quot;
## [1] &quot;Tree 300&quot;
## [1] &quot;Tree 301&quot;
## [1] &quot;Tree 302&quot;
## [1] &quot;Tree 303&quot;
## [1] &quot;Tree 304&quot;
## [1] &quot;Tree 305&quot;
## [1] &quot;Tree 306&quot;
## [1] &quot;Tree 307&quot;
## [1] &quot;Tree 308&quot;
## [1] &quot;Tree 309&quot;
## [1] &quot;Tree 310&quot;
## [1] &quot;Tree 311&quot;
## [1] &quot;Tree 312&quot;
## [1] &quot;Tree 313&quot;
## [1] &quot;Tree 314&quot;
## [1] &quot;Tree 315&quot;
## [1] &quot;Tree 316&quot;
## [1] &quot;Tree 317&quot;
## [1] &quot;Tree 318&quot;
## [1] &quot;Tree 319&quot;
## [1] &quot;Tree 320&quot;
## [1] &quot;Tree 321&quot;
## [1] &quot;Tree 322&quot;
## [1] &quot;Tree 323&quot;
## [1] &quot;Tree 324&quot;
## [1] &quot;Tree 325&quot;
## [1] &quot;Tree 326&quot;
## [1] &quot;Tree 327&quot;
## [1] &quot;Tree 328&quot;
## [1] &quot;Tree 329&quot;
## [1] &quot;Tree 330&quot;
## [1] &quot;Tree 331&quot;
## [1] &quot;Tree 332&quot;
## [1] &quot;Tree 333&quot;
## [1] &quot;Tree 334&quot;
## [1] &quot;Tree 335&quot;
## [1] &quot;Tree 336&quot;
## [1] &quot;Tree 337&quot;
## [1] &quot;Tree 338&quot;
## [1] &quot;Tree 339&quot;
## [1] &quot;Tree 340&quot;
## [1] &quot;Tree 341&quot;
## [1] &quot;Tree 342&quot;
## [1] &quot;Tree 343&quot;
## [1] &quot;Tree 344&quot;
## [1] &quot;Tree 345&quot;
## [1] &quot;Tree 346&quot;
## [1] &quot;Tree 347&quot;
## [1] &quot;Tree 348&quot;
## [1] &quot;Tree 349&quot;
## [1] &quot;Tree 350&quot;
## [1] &quot;Tree 351&quot;
## [1] &quot;Tree 352&quot;
## [1] &quot;Tree 353&quot;
## [1] &quot;Tree 354&quot;
## [1] &quot;Tree 355&quot;
## [1] &quot;Tree 356&quot;
## [1] &quot;Tree 357&quot;
## [1] &quot;Tree 358&quot;
## [1] &quot;Tree 359&quot;
## [1] &quot;Tree 360&quot;
## [1] &quot;Tree 361&quot;
## [1] &quot;Tree 362&quot;
## [1] &quot;Tree 363&quot;
## [1] &quot;Tree 364&quot;
## [1] &quot;Tree 365&quot;
## [1] &quot;Tree 366&quot;
## [1] &quot;Tree 367&quot;
## [1] &quot;Tree 368&quot;
## [1] &quot;Tree 369&quot;
## [1] &quot;Tree 370&quot;
## [1] &quot;Tree 371&quot;
## [1] &quot;Tree 372&quot;
## [1] &quot;Tree 373&quot;
## [1] &quot;Tree 374&quot;
## [1] &quot;Tree 375&quot;
## [1] &quot;Tree 376&quot;
## [1] &quot;Tree 377&quot;
## [1] &quot;Tree 378&quot;
## [1] &quot;Tree 379&quot;
## [1] &quot;Tree 380&quot;
## [1] &quot;Tree 381&quot;
## [1] &quot;Tree 382&quot;
## [1] &quot;Tree 383&quot;
## [1] &quot;Tree 384&quot;
## [1] &quot;Tree 385&quot;
## [1] &quot;Tree 386&quot;
## [1] &quot;Tree 387&quot;
## [1] &quot;Tree 388&quot;
## [1] &quot;Tree 389&quot;
## [1] &quot;Tree 390&quot;
## [1] &quot;Tree 391&quot;
## [1] &quot;Tree 392&quot;
## [1] &quot;Tree 393&quot;
## [1] &quot;Tree 394&quot;
## [1] &quot;Tree 395&quot;
## [1] &quot;Tree 396&quot;
## [1] &quot;Tree 397&quot;
## [1] &quot;Tree 398&quot;
## [1] &quot;Tree 399&quot;
## [1] &quot;Tree 400&quot;
## [1] &quot;Tree 401&quot;
## [1] &quot;Tree 402&quot;
## [1] &quot;Tree 403&quot;
## [1] &quot;Tree 404&quot;
## [1] &quot;Tree 405&quot;
## [1] &quot;Tree 406&quot;
## [1] &quot;Tree 407&quot;
## [1] &quot;Tree 408&quot;
## [1] &quot;Tree 409&quot;
## [1] &quot;Tree 410&quot;
## [1] &quot;Tree 411&quot;
## [1] &quot;Tree 412&quot;
## [1] &quot;Tree 413&quot;
## [1] &quot;Tree 414&quot;
## [1] &quot;Tree 415&quot;
## [1] &quot;Tree 416&quot;
## [1] &quot;Tree 417&quot;
## [1] &quot;Tree 418&quot;
## [1] &quot;Tree 419&quot;
## [1] &quot;Tree 420&quot;
## [1] &quot;Tree 421&quot;
## [1] &quot;Tree 422&quot;
## [1] &quot;Tree 423&quot;
## [1] &quot;Tree 424&quot;
## [1] &quot;Tree 425&quot;
## [1] &quot;Tree 426&quot;
## [1] &quot;Tree 427&quot;
## [1] &quot;Tree 428&quot;
## [1] &quot;Tree 429&quot;
## [1] &quot;Tree 430&quot;
## [1] &quot;Tree 431&quot;
## [1] &quot;Tree 432&quot;
## [1] &quot;Tree 433&quot;
## [1] &quot;Tree 434&quot;
## [1] &quot;Tree 435&quot;
## [1] &quot;Tree 436&quot;
## [1] &quot;Tree 437&quot;
## [1] &quot;Tree 438&quot;
## [1] &quot;Tree 439&quot;
## [1] &quot;Tree 440&quot;
## [1] &quot;Tree 441&quot;
## [1] &quot;Tree 442&quot;
## [1] &quot;Tree 443&quot;
## [1] &quot;Tree 444&quot;
## [1] &quot;Tree 445&quot;
## [1] &quot;Tree 446&quot;
## [1] &quot;Tree 447&quot;
## [1] &quot;Tree 448&quot;
## [1] &quot;Tree 449&quot;
## [1] &quot;Tree 450&quot;
## [1] &quot;Tree 451&quot;
## [1] &quot;Tree 452&quot;
## [1] &quot;Tree 453&quot;
## [1] &quot;Tree 454&quot;
## [1] &quot;Tree 455&quot;
## [1] &quot;Tree 456&quot;
## [1] &quot;Tree 457&quot;
## [1] &quot;Tree 458&quot;
## [1] &quot;Tree 459&quot;
## [1] &quot;Tree 460&quot;
## [1] &quot;Tree 461&quot;
## [1] &quot;Tree 462&quot;
## [1] &quot;Tree 463&quot;
## [1] &quot;Tree 464&quot;
## [1] &quot;Tree 465&quot;
## [1] &quot;Tree 466&quot;
## [1] &quot;Tree 467&quot;
## [1] &quot;Tree 468&quot;
## [1] &quot;Tree 469&quot;
## [1] &quot;Tree 470&quot;
## [1] &quot;Tree 471&quot;
## [1] &quot;Tree 472&quot;
## [1] &quot;Tree 473&quot;
## [1] &quot;Tree 474&quot;
## [1] &quot;Tree 475&quot;
## [1] &quot;Tree 476&quot;
## [1] &quot;Tree 477&quot;
## [1] &quot;Tree 478&quot;
## [1] &quot;Tree 479&quot;
## [1] &quot;Tree 480&quot;
## [1] &quot;Tree 481&quot;
## [1] &quot;Tree 482&quot;
## [1] &quot;Tree 483&quot;
## [1] &quot;Tree 484&quot;
## [1] &quot;Tree 485&quot;
## [1] &quot;Tree 486&quot;
## [1] &quot;Tree 487&quot;
## [1] &quot;Tree 488&quot;
## [1] &quot;Tree 489&quot;
## [1] &quot;Tree 490&quot;
## [1] &quot;Tree 491&quot;
## [1] &quot;Tree 492&quot;
## [1] &quot;Tree 493&quot;
## [1] &quot;Tree 494&quot;
## [1] &quot;Tree 495&quot;
## [1] &quot;Tree 496&quot;
## [1] &quot;Tree 497&quot;
## [1] &quot;Tree 498&quot;
## [1] &quot;Tree 499&quot;
## [1] &quot;Tree 500&quot;
## [1] &quot;Tree 501&quot;
## [1] &quot;Tree 502&quot;
## [1] &quot;Tree 503&quot;
## [1] &quot;Tree 504&quot;
## [1] &quot;Tree 505&quot;
## [1] &quot;Tree 506&quot;
## [1] &quot;Tree 507&quot;
## [1] &quot;Tree 508&quot;
## [1] &quot;Tree 509&quot;
## [1] &quot;Tree 510&quot;
## [1] &quot;Tree 511&quot;
## [1] &quot;Tree 512&quot;
## [1] &quot;Tree 513&quot;
## [1] &quot;Tree 514&quot;
## [1] &quot;Tree 515&quot;
## [1] &quot;Tree 516&quot;
## [1] &quot;Tree 517&quot;
## [1] &quot;Tree 518&quot;
## [1] &quot;Tree 519&quot;
## [1] &quot;Tree 520&quot;
## [1] &quot;Tree 521&quot;
## [1] &quot;Tree 522&quot;
## [1] &quot;Tree 523&quot;
## [1] &quot;Tree 524&quot;
## [1] &quot;Tree 525&quot;
## [1] &quot;Tree 526&quot;
## [1] &quot;Tree 527&quot;
## [1] &quot;Tree 528&quot;
## [1] &quot;Tree 529&quot;
## [1] &quot;Tree 530&quot;
## [1] &quot;Tree 531&quot;
## [1] &quot;Tree 532&quot;
## [1] &quot;Tree 533&quot;
## [1] &quot;Tree 534&quot;
## [1] &quot;Tree 535&quot;
## [1] &quot;Tree 536&quot;
## [1] &quot;Tree 537&quot;
## [1] &quot;Tree 538&quot;
## [1] &quot;Tree 539&quot;
## [1] &quot;Tree 540&quot;
## [1] &quot;Tree 541&quot;
## [1] &quot;Tree 542&quot;
## [1] &quot;Tree 543&quot;
## [1] &quot;Tree 544&quot;
## [1] &quot;Tree 545&quot;
## [1] &quot;Tree 546&quot;
## [1] &quot;Tree 547&quot;
## [1] &quot;Tree 548&quot;
## [1] &quot;Tree 549&quot;
## [1] &quot;Tree 550&quot;
## [1] &quot;Tree 551&quot;
## [1] &quot;Tree 552&quot;
## [1] &quot;Tree 553&quot;
## [1] &quot;Tree 554&quot;
## [1] &quot;Tree 555&quot;
## [1] &quot;Tree 556&quot;
## [1] &quot;Tree 557&quot;
## [1] &quot;Tree 558&quot;
## [1] &quot;Tree 559&quot;
## [1] &quot;Tree 560&quot;
## [1] &quot;Tree 561&quot;
## [1] &quot;Tree 562&quot;
## [1] &quot;Tree 563&quot;
## [1] &quot;Tree 564&quot;
## [1] &quot;Tree 565&quot;
## [1] &quot;Tree 566&quot;
## [1] &quot;Tree 567&quot;
## [1] &quot;Tree 568&quot;
## [1] &quot;Tree 569&quot;
## [1] &quot;Tree 570&quot;
## [1] &quot;Tree 571&quot;
## [1] &quot;Tree 572&quot;
## [1] &quot;Tree 573&quot;
## [1] &quot;Tree 574&quot;
## [1] &quot;Tree 575&quot;
## [1] &quot;Tree 576&quot;
## [1] &quot;Tree 577&quot;
## [1] &quot;Tree 578&quot;
## [1] &quot;Tree 579&quot;
## [1] &quot;Tree 580&quot;
## [1] &quot;Tree 581&quot;
## [1] &quot;Tree 582&quot;
## [1] &quot;Tree 583&quot;
## [1] &quot;Tree 584&quot;
## [1] &quot;Tree 585&quot;
## [1] &quot;Tree 586&quot;
## [1] &quot;Tree 587&quot;
## [1] &quot;Tree 588&quot;
## [1] &quot;Tree 589&quot;
## [1] &quot;Tree 590&quot;
## [1] &quot;Tree 591&quot;
## [1] &quot;Tree 592&quot;
## [1] &quot;Tree 593&quot;
## [1] &quot;Tree 594&quot;
## [1] &quot;Tree 595&quot;
## [1] &quot;Tree 596&quot;
## [1] &quot;Tree 597&quot;
## [1] &quot;Tree 598&quot;
## [1] &quot;Tree 599&quot;
## [1] &quot;Tree 600&quot;
## [1] &quot;Tree 601&quot;
## [1] &quot;Tree 602&quot;
## [1] &quot;Tree 603&quot;
## [1] &quot;Tree 604&quot;
## [1] &quot;Tree 605&quot;
## [1] &quot;Tree 606&quot;
## [1] &quot;Tree 607&quot;
## [1] &quot;Tree 608&quot;
## [1] &quot;Tree 609&quot;
## [1] &quot;Tree 610&quot;
## [1] &quot;Tree 611&quot;
## [1] &quot;Tree 612&quot;
## [1] &quot;Tree 613&quot;
## [1] &quot;Tree 614&quot;
## [1] &quot;Tree 615&quot;
## [1] &quot;Tree 616&quot;
## [1] &quot;Tree 617&quot;
## [1] &quot;Tree 618&quot;
## [1] &quot;Tree 619&quot;
## [1] &quot;Tree 620&quot;
## [1] &quot;Tree 621&quot;
## [1] &quot;Tree 622&quot;
## [1] &quot;Tree 623&quot;
## [1] &quot;Tree 624&quot;
## [1] &quot;Tree 625&quot;
## [1] &quot;Tree 626&quot;
## [1] &quot;Tree 627&quot;
## [1] &quot;Tree 628&quot;
## [1] &quot;Tree 629&quot;
## [1] &quot;Tree 630&quot;
## [1] &quot;Tree 631&quot;
## [1] &quot;Tree 632&quot;
## [1] &quot;Tree 633&quot;
## [1] &quot;Tree 634&quot;
## [1] &quot;Tree 635&quot;
## [1] &quot;Tree 636&quot;
## [1] &quot;Tree 637&quot;
## [1] &quot;Tree 638&quot;
## [1] &quot;Tree 639&quot;
## [1] &quot;Tree 640&quot;
## [1] &quot;Tree 641&quot;
## [1] &quot;Tree 642&quot;
## [1] &quot;Tree 643&quot;
## [1] &quot;Tree 644&quot;
## [1] &quot;Tree 645&quot;
## [1] &quot;Tree 646&quot;
## [1] &quot;Tree 647&quot;
## [1] &quot;Tree 648&quot;
## [1] &quot;Tree 649&quot;
## [1] &quot;Tree 650&quot;
## [1] &quot;Tree 651&quot;
## [1] &quot;Tree 652&quot;
## [1] &quot;Tree 653&quot;
## [1] &quot;Tree 654&quot;
## [1] &quot;Tree 655&quot;
## [1] &quot;Tree 656&quot;
## [1] &quot;Tree 657&quot;
## [1] &quot;Tree 658&quot;
## [1] &quot;Tree 659&quot;
## [1] &quot;Tree 660&quot;
## [1] &quot;Tree 661&quot;
## [1] &quot;Tree 662&quot;
## [1] &quot;Tree 663&quot;
## [1] &quot;Tree 664&quot;
## [1] &quot;Tree 665&quot;
## [1] &quot;Tree 666&quot;
## [1] &quot;Tree 667&quot;
## [1] &quot;Tree 668&quot;
## [1] &quot;Tree 669&quot;
## [1] &quot;Tree 670&quot;
## [1] &quot;Tree 671&quot;
## [1] &quot;Tree 672&quot;
## [1] &quot;Tree 673&quot;
## [1] &quot;Tree 674&quot;
## [1] &quot;Tree 675&quot;
## [1] &quot;Tree 676&quot;
## [1] &quot;Tree 677&quot;
## [1] &quot;Tree 678&quot;
## [1] &quot;Tree 679&quot;
## [1] &quot;Tree 680&quot;
## [1] &quot;Tree 681&quot;
## [1] &quot;Tree 682&quot;
## [1] &quot;Tree 683&quot;
## [1] &quot;Tree 684&quot;
## [1] &quot;Tree 685&quot;
## [1] &quot;Tree 686&quot;
## [1] &quot;Tree 687&quot;
## [1] &quot;Tree 688&quot;
## [1] &quot;Tree 689&quot;
## [1] &quot;Tree 690&quot;
## [1] &quot;Tree 691&quot;
## [1] &quot;Tree 692&quot;
## [1] &quot;Tree 693&quot;
## [1] &quot;Tree 694&quot;
## [1] &quot;Tree 695&quot;
## [1] &quot;Tree 696&quot;
## [1] &quot;Tree 697&quot;
## [1] &quot;Tree 698&quot;
## [1] &quot;Tree 699&quot;
## [1] &quot;Tree 700&quot;
## [1] &quot;Tree 701&quot;
## [1] &quot;Tree 702&quot;
## [1] &quot;Tree 703&quot;
## [1] &quot;Tree 704&quot;
## [1] &quot;Tree 705&quot;
## [1] &quot;Tree 706&quot;
## [1] &quot;Tree 707&quot;
## [1] &quot;Tree 708&quot;
## [1] &quot;Tree 709&quot;
## [1] &quot;Tree 710&quot;
## [1] &quot;Tree 711&quot;
## [1] &quot;Tree 712&quot;
## [1] &quot;Tree 713&quot;
## [1] &quot;Tree 714&quot;
## [1] &quot;Tree 715&quot;
## [1] &quot;Tree 716&quot;
## [1] &quot;Tree 717&quot;
## [1] &quot;Tree 718&quot;
## [1] &quot;Tree 719&quot;
## [1] &quot;Tree 720&quot;
## [1] &quot;Tree 721&quot;
## [1] &quot;Tree 722&quot;
## [1] &quot;Tree 723&quot;
## [1] &quot;Tree 724&quot;
## [1] &quot;Tree 725&quot;
## [1] &quot;Tree 726&quot;
## [1] &quot;Tree 727&quot;
## [1] &quot;Tree 728&quot;
## [1] &quot;Tree 729&quot;
## [1] &quot;Tree 730&quot;
## [1] &quot;Tree 731&quot;
## [1] &quot;Tree 732&quot;
## [1] &quot;Tree 733&quot;
## [1] &quot;Tree 734&quot;
## [1] &quot;Tree 735&quot;
## [1] &quot;Tree 736&quot;
## [1] &quot;Tree 737&quot;
## [1] &quot;Tree 738&quot;
## [1] &quot;Tree 739&quot;
## [1] &quot;Tree 740&quot;
## [1] &quot;Tree 741&quot;
## [1] &quot;Tree 742&quot;
## [1] &quot;Tree 743&quot;
## [1] &quot;Tree 744&quot;
## [1] &quot;Tree 745&quot;
## [1] &quot;Tree 746&quot;
## [1] &quot;Tree 747&quot;
## [1] &quot;Tree 748&quot;
## [1] &quot;Tree 749&quot;
## [1] &quot;Tree 750&quot;
## [1] &quot;Tree 751&quot;
## [1] &quot;Tree 752&quot;
## [1] &quot;Tree 753&quot;
## [1] &quot;Tree 754&quot;
## [1] &quot;Tree 755&quot;
## [1] &quot;Tree 756&quot;
## [1] &quot;Tree 757&quot;
## [1] &quot;Tree 758&quot;
## [1] &quot;Tree 759&quot;
## [1] &quot;Tree 760&quot;
## [1] &quot;Tree 761&quot;
## [1] &quot;Tree 762&quot;
## [1] &quot;Tree 763&quot;
## [1] &quot;Tree 764&quot;
## [1] &quot;Tree 765&quot;
## [1] &quot;Tree 766&quot;
## [1] &quot;Tree 767&quot;
## [1] &quot;Tree 768&quot;
## [1] &quot;Tree 769&quot;
## [1] &quot;Tree 770&quot;
## [1] &quot;Tree 771&quot;
## [1] &quot;Tree 772&quot;
## [1] &quot;Tree 773&quot;
## [1] &quot;Tree 774&quot;
## [1] &quot;Tree 775&quot;
## [1] &quot;Tree 776&quot;
## [1] &quot;Tree 777&quot;
## [1] &quot;Tree 778&quot;
## [1] &quot;Tree 779&quot;
## [1] &quot;Tree 780&quot;
## [1] &quot;Tree 781&quot;
## [1] &quot;Tree 782&quot;
## [1] &quot;Tree 783&quot;
## [1] &quot;Tree 784&quot;
## [1] &quot;Tree 785&quot;
## [1] &quot;Tree 786&quot;
## [1] &quot;Tree 787&quot;
## [1] &quot;Tree 788&quot;
## [1] &quot;Tree 789&quot;
## [1] &quot;Tree 790&quot;
## [1] &quot;Tree 791&quot;
## [1] &quot;Tree 792&quot;
## [1] &quot;Tree 793&quot;
## [1] &quot;Tree 794&quot;
## [1] &quot;Tree 795&quot;
## [1] &quot;Tree 796&quot;
## [1] &quot;Tree 797&quot;
## [1] &quot;Tree 798&quot;
## [1] &quot;Tree 799&quot;
## [1] &quot;Tree 800&quot;
## [1] &quot;Tree 801&quot;
## [1] &quot;Tree 802&quot;
## [1] &quot;Tree 803&quot;
## [1] &quot;Tree 804&quot;
## [1] &quot;Tree 805&quot;
## [1] &quot;Tree 806&quot;
## [1] &quot;Tree 807&quot;
## [1] &quot;Tree 808&quot;
## [1] &quot;Tree 809&quot;
## [1] &quot;Tree 810&quot;
## [1] &quot;Tree 811&quot;
## [1] &quot;Tree 812&quot;
## [1] &quot;Tree 813&quot;
## [1] &quot;Tree 814&quot;
## [1] &quot;Tree 815&quot;
## [1] &quot;Tree 816&quot;
## [1] &quot;Tree 817&quot;
## [1] &quot;Tree 818&quot;
## [1] &quot;Tree 819&quot;
## [1] &quot;Tree 820&quot;
## [1] &quot;Tree 821&quot;
## [1] &quot;Tree 822&quot;
## [1] &quot;Tree 823&quot;
## [1] &quot;Tree 824&quot;
## [1] &quot;Tree 825&quot;
## [1] &quot;Tree 826&quot;
## [1] &quot;Tree 827&quot;
## [1] &quot;Tree 828&quot;
## [1] &quot;Tree 829&quot;
## [1] &quot;Tree 830&quot;
## [1] &quot;Tree 831&quot;
## [1] &quot;Tree 832&quot;
## [1] &quot;Tree 833&quot;
## [1] &quot;Tree 834&quot;
## [1] &quot;Tree 835&quot;
## [1] &quot;Tree 836&quot;
## [1] &quot;Tree 837&quot;
## [1] &quot;Tree 838&quot;
## [1] &quot;Tree 839&quot;
## [1] &quot;Tree 840&quot;
## [1] &quot;Tree 841&quot;
## [1] &quot;Tree 842&quot;
## [1] &quot;Tree 843&quot;
## [1] &quot;Tree 844&quot;
## [1] &quot;Tree 845&quot;
## [1] &quot;Tree 846&quot;
## [1] &quot;Tree 847&quot;
## [1] &quot;Tree 848&quot;
## [1] &quot;Tree 849&quot;
## [1] &quot;Tree 850&quot;
## [1] &quot;Tree 851&quot;
## [1] &quot;Tree 852&quot;
## [1] &quot;Tree 853&quot;
## [1] &quot;Tree 854&quot;
## [1] &quot;Tree 855&quot;
## [1] &quot;Tree 856&quot;
## [1] &quot;Tree 857&quot;
## [1] &quot;Tree 858&quot;
## [1] &quot;Tree 859&quot;
## [1] &quot;Tree 860&quot;
## [1] &quot;Tree 861&quot;
## [1] &quot;Tree 862&quot;
## [1] &quot;Tree 863&quot;
## [1] &quot;Tree 864&quot;
## [1] &quot;Tree 865&quot;
## [1] &quot;Tree 866&quot;
## [1] &quot;Tree 867&quot;
## [1] &quot;Tree 868&quot;
## [1] &quot;Tree 869&quot;
## [1] &quot;Tree 870&quot;
## [1] &quot;Tree 871&quot;
## [1] &quot;Tree 872&quot;
## [1] &quot;Tree 873&quot;
## [1] &quot;Tree 874&quot;
## [1] &quot;Tree 875&quot;
## [1] &quot;Tree 876&quot;
## [1] &quot;Tree 877&quot;
## [1] &quot;Tree 878&quot;
## [1] &quot;Tree 879&quot;
## [1] &quot;Tree 880&quot;
## [1] &quot;Tree 881&quot;
## [1] &quot;Tree 882&quot;
## [1] &quot;Tree 883&quot;
## [1] &quot;Tree 884&quot;
## [1] &quot;Tree 885&quot;
## [1] &quot;Tree 886&quot;
## [1] &quot;Tree 887&quot;
## [1] &quot;Tree 888&quot;
## [1] &quot;Tree 889&quot;
## [1] &quot;Tree 890&quot;
## [1] &quot;Tree 891&quot;
## [1] &quot;Tree 892&quot;
## [1] &quot;Tree 893&quot;
## [1] &quot;Tree 894&quot;
## [1] &quot;Tree 895&quot;
## [1] &quot;Tree 896&quot;
## [1] &quot;Tree 897&quot;
## [1] &quot;Tree 898&quot;
## [1] &quot;Tree 899&quot;
## [1] &quot;Tree 900&quot;
## [1] &quot;Tree 901&quot;
## [1] &quot;Tree 902&quot;
## [1] &quot;Tree 903&quot;
## [1] &quot;Tree 904&quot;
## [1] &quot;Tree 905&quot;
## [1] &quot;Tree 906&quot;
## [1] &quot;Tree 907&quot;
## [1] &quot;Tree 908&quot;
## [1] &quot;Tree 909&quot;
## [1] &quot;Tree 910&quot;
## [1] &quot;Tree 911&quot;
## [1] &quot;Tree 912&quot;
## [1] &quot;Tree 913&quot;
## [1] &quot;Tree 914&quot;
## [1] &quot;Tree 915&quot;
## [1] &quot;Tree 916&quot;
## [1] &quot;Tree 917&quot;
## [1] &quot;Tree 918&quot;
## [1] &quot;Tree 919&quot;
## [1] &quot;Tree 920&quot;
## [1] &quot;Tree 921&quot;
## [1] &quot;Tree 922&quot;
## [1] &quot;Tree 923&quot;
## [1] &quot;Tree 924&quot;
## [1] &quot;Tree 925&quot;
## [1] &quot;Tree 926&quot;
## [1] &quot;Tree 927&quot;
## [1] &quot;Tree 928&quot;
## [1] &quot;Tree 929&quot;
## [1] &quot;Tree 930&quot;
## [1] &quot;Tree 931&quot;
## [1] &quot;Tree 932&quot;
## [1] &quot;Tree 933&quot;
## [1] &quot;Tree 934&quot;
## [1] &quot;Tree 935&quot;
## [1] &quot;Tree 936&quot;
## [1] &quot;Tree 937&quot;
## [1] &quot;Tree 938&quot;
## [1] &quot;Tree 939&quot;
## [1] &quot;Tree 940&quot;
## [1] &quot;Tree 941&quot;
## [1] &quot;Tree 942&quot;
## [1] &quot;Tree 943&quot;
## [1] &quot;Tree 944&quot;
## [1] &quot;Tree 945&quot;
## [1] &quot;Tree 946&quot;
## [1] &quot;Tree 947&quot;
## [1] &quot;Tree 948&quot;
## [1] &quot;Tree 949&quot;
## [1] &quot;Tree 950&quot;
## [1] &quot;Tree 951&quot;
## [1] &quot;Tree 952&quot;
## [1] &quot;Tree 953&quot;
## [1] &quot;Tree 954&quot;
## [1] &quot;Tree 955&quot;
## [1] &quot;Tree 956&quot;
## [1] &quot;Tree 957&quot;
## [1] &quot;Tree 958&quot;
## [1] &quot;Tree 959&quot;
## [1] &quot;Tree 960&quot;
## [1] &quot;Tree 961&quot;
## [1] &quot;Tree 962&quot;
## [1] &quot;Tree 963&quot;
## [1] &quot;Tree 964&quot;
## [1] &quot;Tree 965&quot;
## [1] &quot;Tree 966&quot;
## [1] &quot;Tree 967&quot;
## [1] &quot;Tree 968&quot;
## [1] &quot;Tree 969&quot;
## [1] &quot;Tree 970&quot;
## [1] &quot;Tree 971&quot;
## [1] &quot;Tree 972&quot;
## [1] &quot;Tree 973&quot;
## [1] &quot;Tree 974&quot;
## [1] &quot;Tree 975&quot;
## [1] &quot;Tree 976&quot;
## [1] &quot;Tree 977&quot;
## [1] &quot;Tree 978&quot;
## [1] &quot;Tree 979&quot;
## [1] &quot;Tree 980&quot;
## [1] &quot;Tree 981&quot;
## [1] &quot;Tree 982&quot;
## [1] &quot;Tree 983&quot;
## [1] &quot;Tree 984&quot;
## [1] &quot;Tree 985&quot;
## [1] &quot;Tree 986&quot;
## [1] &quot;Tree 987&quot;
## [1] &quot;Tree 988&quot;
## [1] &quot;Tree 989&quot;
## [1] &quot;Tree 990&quot;
## [1] &quot;Tree 991&quot;
## [1] &quot;Tree 992&quot;
## [1] &quot;Tree 993&quot;
## [1] &quot;Tree 994&quot;
## [1] &quot;Tree 995&quot;
## [1] &quot;Tree 996&quot;
## [1] &quot;Tree 997&quot;
## [1] &quot;Tree 998&quot;
## [1] &quot;Tree 999&quot;
## [1] &quot;Tree 1000&quot;
</code></pre>

<pre><code class="r">predictions = predict(forest, X.test)
forest.ci = randomForestInfJack(forest, X.test, calibrate = TRUE)
</code></pre>

</body>

</html>

